package com.example.yy.fragementtest318yy.activity;

import android.app.ProgressDialog;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import com.example.yy.fragementtest318yy.R;

public class ViewVideoActivity extends AppCompatActivity {
    private VideoView videoview;
    private String path="";
    private String BASEURL="http://amicool.neusoft.edu.cn/";
    private ProgressDialog dialog;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_video);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);//透明
        videoview=(VideoView)findViewById(R.id.videoview);
        path=BASEURL+"Uploads/video/video/"+getIntent().getStringExtra("videopath");
        dialog=ProgressDialog.show(ViewVideoActivity.this, "视频加载中...", "请您稍候");
        Uri uri = Uri.parse(path);
        videoview.setMediaController(new MediaController(this));
        videoview.setVideoURI(uri);
        videoview.setOnPreparedListener(new MyPlayerOnPreparedListener());
        videoview.setOnCompletionListener( new MyPlayerOnCompletionListener());//播放完成回调
        videoview.requestFocus();// 让VideoView获取焦点
        videoview.start();//开始播放

    }

    class MyPlayerOnPreparedListener implements MediaPlayer.OnPreparedListener{

        @Override
        public void onPrepared(MediaPlayer mp) {
            videoview.setBackgroundColor(Color.argb(0,0,255,0));
            dialog.dismiss();
        }
    }
    class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener{

        @Override
        public void onCompletion(MediaPlayer mp) {
            Toast.makeText( ViewVideoActivity.this, "播放完成", Toast.LENGTH_SHORT).show();
        }
    }


}
